package com.deyu.util;

import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

public class NormalStrategy implements ExclusionStrategy{
	private static Logger log = LoggerFactory.getLogger(NormalStrategy.class);
	private Class<?> target;   
	private String[] fields;   
	private Class<?> clazz;  
	private String[] clazzFields;   
    private Class<?> clazz2;
    private String[] clazzFields2;
    private Class<?> clazz3;
    private String[] clazzFields3;
    private Class<?> clazz4;
    private String[] clazzFields4;
    private Class<?> clazz5;
    private String[] clazzFields5;
	private boolean reverse;   

	public NormalStrategy(Class<?> target) {
		super();
		this.target = target;
	}

	@Override
	public boolean shouldSkipClass(Class<?> class1) {
		return false;
	}

	@Override
	public boolean shouldSkipField(FieldAttributes fieldattributes) {
		Class<?> owner = fieldattributes.getDeclaringClass();
		Class<?> c = fieldattributes.getDeclaredClass();
		String f = fieldattributes.getName();
		boolean isSkip = false;
		//Ŀ��class
		if (owner == target) {
			if (ArrayUtils.contains(fields, f)) {
				log.debug("fitler field:{} for class:{}", f, owner);
				isSkip = true;
			}
		}
		//���⴦��class
		else if(owner == clazz){
			if(ArrayUtils.contains(clazzFields, f)){
				isSkip = true;
			}
		}
		else if(owner == clazz2){
			if(ArrayUtils.contains(clazzFields2, f)){
				isSkip = true;
			}
		}
		else if(owner == clazz3){
			if(ArrayUtils.contains(clazzFields3, f)){
				isSkip = true;
			}
		}
		else if(owner == clazz4){
			if(ArrayUtils.contains(clazzFields4, f)){
				isSkip = true;
			}
		}
		if (reverse) {
			isSkip = !isSkip;
		}
		return isSkip;
	}

	public void setFields(String[] fields) {
		this.fields = fields;
	}

	public void setClazz(Class<?> clazz) {
		this.clazz = clazz;
	}
	

	public void setClazz2(Class<?> clazz2) {
		this.clazz2 = clazz2;
	}

	public String[] getClazzFields() {
		return clazzFields;
	}

	public void setClazzFields(String[] clazzFields) {
		this.clazzFields = clazzFields;
	}
	
	public String[] getClazzFields2() {
		return clazzFields2;
	}

	public void setClazzFields2(String[] clazzFields2) {
		this.clazzFields2 = clazzFields2;
	}

	public void setClazz3(Class<?> clazz3) {
		this.clazz3 = clazz3;
	}

	public String[] getClazzFields3() {
		return clazzFields3;
	}

	public void setClazzFields3(String[] clazzFields3) {
		this.clazzFields3 = clazzFields3;
	}

	public void setClazz4(Class<?> clazz4) {
		this.clazz4 = clazz4;
	}

	public String[] getClazzFields4() {
		return clazzFields4;
	}

	public void setClazzFields4(String[] clazzFields4) {
		this.clazzFields4 = clazzFields4;
	}
	public void setClazz5(Class<?> clazz5) {
		this.clazz5 = clazz5;
	}

	public String[] getClazzFields5() {
		return clazzFields5;
	}

	public void setClazzFields5(String[] clazzFields5) {
		this.clazzFields5 = clazzFields5;
	}
	public void setReverse(boolean reverse) {
		this.reverse = reverse;
	}

	
}
